package cn.wolfcode.p2p.controller;

import cn.wolfcode.p2p.business.query.BidRequestAuditQueryObject;
import cn.wolfcode.p2p.business.service.IBidRequestService;
import cn.wolfcode.p2p.business.service.IBidRequestAuditHistoryService;
import cn.wolfcode.p2p.util.Constants;
import cn.wolfcode.p2p.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

/**
 * 后台审核
 */
@Controller
public class BidRequestAuditController {

    @Autowired
    private IBidRequestService bidRequestService;

    /**
     * 显示需要审核的信息
     *
     * @param qo
     * @param model
     * @return
     */
    @RequestMapping("bidrequest_publishaudit_list")
    public String bidrequestPublishauditList(@ModelAttribute("qo") BidRequestAuditQueryObject qo, Model model) {

        qo.setState(Constants.BIDREQUEST_STATE_APPLYING);
        qo.setState(Constants.BIDREQUEST_STATE_APPLYING);
        model.addAttribute("pageInfo", bidRequestService.listForPage(qo));
        return "bidrequest/publish_audit";
    }

    /**
     * 保存审核后的信息
     *
     * @return
     */
    @RequestMapping("bidrequest_publishaudit")
    @ResponseBody
    public JsonResult bidrequestPublishAudit(Long id, String remark, Integer state, @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss") Date publishTime) {

        bidRequestService.publishAudit(id, remark, state, publishTime);
        return JsonResult.instance();
    }

    /**
     * 满标一审列表
     * @param qo  分页
     * @param model
     * @return
     */
    @RequestMapping("bidrequest_audit1_list")
    public String bidrequestAudit1List(@ModelAttribute("qo") BidRequestAuditQueryObject qo,Model model){

        qo.setState(Constants.BIDREQUEST_STATE_APPROVE_PENDING_1);
        model.addAttribute("pageInfo", bidRequestService.listForPage(qo));
        return "bidrequest/audit1";
    }

    /**
     * 满标一审审核申请
     * @param id
     * @param remark
     * @param state 审核成功/拒绝
     * @return
     */
    @RequestMapping("bidrequest_audit1")
    @ResponseBody
    public JsonResult bidrequestAudit1(Long id, String remark, Integer state){

        bidRequestService.fullAudit1(id,remark,state);
        return JsonResult.instance();
    }



    /**
     * 满标二审列表
     * @param qo  分页
     * @param model
     * @return
     */
    @RequestMapping("bidrequest_audit2_list")
    public String bidrequestAudit2List(@ModelAttribute("qo") BidRequestAuditQueryObject qo,Model model){
        qo.setState(Constants.BIDREQUEST_STATE_APPROVE_PENDING_2);
        model.addAttribute("pageInfo", bidRequestService.listForPage(qo));
        return "bidrequest/audit2";
    }

    /**
     * 满标二审审核申请
     * @param id
     * @param remark
     * @param state 审核成功/拒绝
     * @return
     */
    @RequestMapping("bidrequest_audit2")
    @ResponseBody
    public JsonResult bidrequestAudit2(Long id, String remark, Integer state){

        bidRequestService.fullAudit2(id,remark,state);
        return JsonResult.instance();
    }
}
